//
//  VerticalCell.m
//  MasonryViewDemo
//
//  Created by Sarp Erdag on 3/30/12.
//  Copyright (c) 2012 Apperto. All rights reserved.
//

#import "VerticalCell.h"
#import "MediaListsMedia.h"
#import "Split.h"
#import "LoadingUI.h"

#define IMAGETAG_TAG 100000
#define IMAGELOGO_TAG 30000000

@implementation VerticalCell
@synthesize IVw_Logo, IVw_Tag;

- (void) updateCellInfo:(MediaListsMedia *)Media {
    
    IVw_Tag.tag = IMAGETAG_TAG;
    IVw_Logo.tag = IMAGELOGO_TAG;
    
    self.IVw_Logo.image = [[UIImage alloc] initWithContentsOfFile:[LoadingUI IconPressed:Media.NS_Source]];
    
    float ratio;
    
    if (Media.imageArray.count!=0) {
        
        imageView.contentMode = UIViewContentModeCenter;
        MediaListsImage *MLI_Image = [Media.imageArray objectAtIndex:0];
        
        //Check image
        if (([MLI_Image.image_filename rangeOfString:@"safe_image.php"].location == NSNotFound)&&
            ([MLI_Image.image_filename rangeOfString:@"app_full_proxy.php"].location == NSNotFound)) {
            
            //Check Source of Media.
            if (MLI_Image.Height!=0) {
                ratio = imageView.frame.size.width/MLI_Image.Width;
                self.imageHeight = MLI_Image.Height*ratio;
            }
            else
                self.imageHeight = 100 + arc4random() % 150;
            
            self.imageURL = [NSString stringWithFormat:@"%@",MLI_Image.image_filename];
            self.imageWidth = imageView.frame.size.width;
        }
        else
            imageView.frame = CGRectMake(0, 0, 0, 0);
    }
    else if (Media.MLH_html.NS_ImageName!=nil) {
        
        imageView.contentMode = UIViewContentModeCenter;
        ratio = imageView.frame.size.width/Media.MLH_html.ImageWidth;
        self.imageHeight = Media.MLH_html.ImageHeight*ratio;
        self.imageURL = [NSString stringWithFormat:@"%@",Media.MLH_html.NS_ImageName];
        self.imageWidth = imageView.frame.size.width;
        
    }
    else
        imageView.frame = CGRectMake(0, 0, 0, 0);
     
    //Check Title display
    if((![Media.text.text_title isEqualToString:@""])&&(Media.text.text_title!=nil))
        self.text = [Media.text.text_title TitleSplitPressed];
    else if((![Media.MLH_html.NS_htmlTitle isEqualToString:@""])&&(Media.MLH_html.NS_htmlTitle!=nil))
        self.text = [Media.MLH_html.NS_htmlTitle TitleSplitPressed];
    else if((![Media.text.text_description isEqualToString:@""])&&(Media.text.text_description!=nil))
        self.text = [Media.text.text_description TitleSplitPressed];
    
    if(([self.text isEqualToString:@""])||(self.text==nil)) {
        self.text = @"  ";
        titleLabel.textColor = [UIColor whiteColor];
    }
    
    [super updateCellInfo:Media];
}

@end
